package com.hison.courseselectionsystem.controller;


import com.hison.courseselectionsystem.domain.Student;
import com.hison.courseselectionsystem.dto.LoginFormByPhone;
import com.hison.courseselectionsystem.dto.LoginFormById;
import com.hison.courseselectionsystem.service.StudentService;
import com.hison.courseselectionsystem.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: StudentController
 * @Descripiton: 学生控制类
 * @Author: 小郑
 * @Date： 2023/11/16 22:28
 * @Version：1.8
 **/
@Api(value = "学生接口",description = "学生接口，提供学生的注册、登录、查看当前用户信息、修改密码等等")
@RequestMapping("/student")
@RestController
public class StudentController {
    @Autowired
    private StudentService  studentService;


    /**
     * 用户注册
     * @param student
     * @return {@link Result}
     */
    @ApiOperation(value = "用户注册接口",notes = "供用户注册，默认密码123456",produces = "application/json")
    @PostMapping("/register")
    public Result register(@RequestBody Student  student){
        return  studentService.register(student);
    }

    /**
     * 用户登录接口   通过账号密码登录
     * @param loginFormByStuId
     * @return {@link Result}
     */
    @ApiOperation(value = "用户登录接口",notes = "用户通过学号和密码登录",produces = "application/json")
    @PostMapping("/loginbystuid")
    public Result login(@RequestBody LoginFormById loginFormByStuId) {
        return studentService.login(loginFormByStuId);
    }


    /**
     * 发送手机验证码
     */
    @ApiOperation(value = "获取验证码",notes = "通过手机号获取验证码",produces = "application/json")
    @PostMapping("code")
    public Result sendCode(@RequestParam("phone") String phone) {
        //  发送短信验证码并保存验证码
        return studentService.sendCode(phone);
    }



    /**
     * 用户登录接口   手机验证码
     * @param loginFormByPhone
     * @return {@link Result}
     */
    @ApiOperation(value = "用户登录接口",notes = "用户通过手机验证码登录",produces = "application/json")
    @PostMapping("/loginbyphone")
    public Result login(@RequestBody LoginFormByPhone loginFormByPhone) {
        return studentService.login(loginFormByPhone);
    }


    /**
     * 查看的当前用户信息
     * @return {@link Result}
     */
    @ApiOperation(value = "查看个人信息",notes = "根据学号查看个人信息")
    @GetMapping("/me")
    public Result getUserInfo(@RequestParam("stuid") String stuid){
        return studentService.getUserInfo(stuid);
    }

    //修改当前用户信息
    @ApiOperation(value = "修改用户信息",notes = "修改学生信息",produces = "application/json")
    @PutMapping("/update")
    public Result updateUser(@RequestBody Student student) {
        return studentService.updateUser(student);
    }

    /**
     * 修改密码
     * @param oldpwd
     * @param newpwd
     * @return {@link Result}
     */
    @ApiOperation(value = "修改密码",notes = "修改学生密码",produces = "application/json")
    @PutMapping("/updatepwd")
    public Result updateUser(@RequestParam("stuid")String stuId,@RequestParam("oldpwd") String oldpwd,@RequestParam("newpwd") String newpwd) {
        return studentService.updatepwd(stuId,oldpwd,newpwd);
    }

    /**
     * @param phone
     * @param stuid
     * @return {@link Result}
     */
    @ApiOperation(value = "找回密码",notes = "找回密码功能",produces = "application/json")
    @PostMapping("/findPwd")
    public  Result findPwd(@RequestParam("phone") String phone,@RequestParam("stuid") String  stuid){
        return  studentService.findPwd(phone,stuid);
    }
}